<?php

/**
 * Carte filter form base class.
 *
 * @package    Librarie
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseCarteFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'titlu'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'editura'        => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'an_aparietie'   => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'pret'           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'editie'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'volum'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'stoc'           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'poza'           => new sfWidgetFormFilterInput(),
      'data_adaugarii' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'autor_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Autor')),
      'comanda_list'   => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Comanda')),
    ));

    $this->setValidators(array(
      'titlu'          => new sfValidatorPass(array('required' => false)),
      'editura'        => new sfValidatorPass(array('required' => false)),
      'an_aparietie'   => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'pret'           => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'editie'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'volum'          => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'stoc'           => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'poza'           => new sfValidatorPass(array('required' => false)),
      'data_adaugarii' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'autor_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Autor', 'required' => false)),
      'comanda_list'   => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Comanda', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('carte_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addAutorListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.cartiAutor cartiAutor')
      ->andWhereIn('cartiAutor.id_autor', $values)
    ;
  }

  public function addComandaListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.listaCarti listaCarti')
      ->andWhereIn('listaCarti.id_comanda', $values)
    ;
  }

  public function getModelName()
  {
    return 'Carte';
  }

  public function getFields()
  {
    return array(
      'id_carte'       => 'Number',
      'titlu'          => 'Text',
      'editura'        => 'Text',
      'an_aparietie'   => 'Number',
      'pret'           => 'Number',
      'editie'         => 'Number',
      'volum'          => 'Number',
      'stoc'           => 'Number',
      'poza'           => 'Text',
      'data_adaugarii' => 'Date',
      'autor_list'     => 'ManyKey',
      'comanda_list'   => 'ManyKey',
    );
  }
}
